package com.kingland.hailin.controller;

import com.kingland.hailin.model.UserModel;
import com.kingland.hailin.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/*
@Name: UserController
@Author: zhouhailin
@Date: 2021/5/25
@Time: 7:54 下午
@Description： 
*/
@RestController
public class UserController {


    private UserService userService;

    //构造器注入 避免相互创建的问题  依赖倒置原则
    public UserController(UserService userService) {
        this.userService = userService;
    }


    @PostMapping("/user")
    public UserModel addUser(@RequestBody UserModel userModel) {
        return this.userService.addUser(userModel);
    }

    @GetMapping("/")
    public ResponseEntity<List<UserModel>> findAll() {
        return new ResponseEntity<List<UserModel>>(userService.findAll(), HttpStatus.OK);
    }

}
